﻿#region Using

using System;

using Common.Base;

using GameLogic.External;

using ServerApplication.Enums;

#endregion

namespace ServerApplication.Networking
{
    public class ServerPlayer : Identifiable, IPlayerHeader
    {
        private ServerPlayerState state;

        public ServerPlayer(string name)
        {
            this.state = ServerPlayerState.Connected;
            this.Name = name;
        }

        private ServerPlayer(string name, int id)
            : base(id)
        {
            this.Name = name;
        }

        public static ServerPlayer EmptyPlayer
        {
            get
            {
                return new ServerPlayer(string.Empty, -1);
            }
        }

        public ServerPlayerState ServerPlayerState
        {
            get
            {
                return this.state;
            }

            set
            {
                if (this.state != ServerPlayerState.Disconnected)
                {
                    this.state = value;
                    this.Disconnected(this, new EventArgs());
                }
            }
        }

        public string Name { get; private set; }

        public event EventHandler Disconnected;
    }
}